package com.huawei.chengdu.meetingdemo.view.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.huawei.chengdu.meetingdemo.R;

import java.util.HashMap;
import java.util.Map;

public class BandwidthSelectDialog extends Dialog {
    public static final Map<Integer, String> bandwidthMap = new HashMap();
    public RadioGroup bandwidthSelect;
    public TextView bandwidthConfirm;

    public BandwidthSelectDialog(@NonNull Context context) {
        super(context);
        setContentView(R.layout.dialog_bandwidth_select);
        initView();
        initBandwidthMap();
    }

    private void initView() {
        bandwidthSelect = findViewById(R.id.bandwidth_select);
        bandwidthConfirm = findViewById(R.id.bandwidth_confirm);
    }

    public void setCheckedBandwidth(int bandwidth) {
        for (int i = 0; i < bandwidthSelect.getChildCount(); i++) {
            RadioButton curRadioButton = (RadioButton) bandwidthSelect.getChildAt(i);
            if (Integer.parseInt(curRadioButton.getTag().toString()) == bandwidth) {
                curRadioButton.setChecked(true);
                break;
            }
        }
    }

    @Override
    public void show() {
        setCanceledOnTouchOutside(false);
        super.show();
    }

    private void initBandwidthMap() {
        if (bandwidthMap.size() > 0) {
            return;
        }
        bandwidthMap.put(64, "64 kbps");
        bandwidthMap.put(128, "128 kbps");
        bandwidthMap.put(192, "192 kbps");
        bandwidthMap.put(256, "256 kbps");
        bandwidthMap.put(320, "320 kbps");
        bandwidthMap.put(384, "384 kbps");
        bandwidthMap.put(512, "512 kbps");
        bandwidthMap.put(768, "768 kbps");
        bandwidthMap.put(1024, "1024 kbps");
        bandwidthMap.put(1152, "1152 kbps");
        bandwidthMap.put(1472, "1472 kbps");
        bandwidthMap.put(1536, "1536 kbps");
        bandwidthMap.put(1920, "1920 kbps");
        bandwidthMap.put(2048, "2048 kbps");
        bandwidthMap.put(2880, "3 Mbps");
        bandwidthMap.put(3840, "4 Mbps");
        bandwidthMap.put(4800, "5 Mbps");
        bandwidthMap.put(5760, "6 Mbps");
        bandwidthMap.put(6720, "7 Mbps");
        bandwidthMap.put(7680, "8 Mbps");
    }
}
